package server;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Iterator;
import java.util.Vector;

import client.Remote;

public class Buffer_test {

	public static void main(String[] args) throws Exception {
		CharBuffer buff = CharBuffer.allocate(2048);

		// Initialization of the samples
		Vector<String> list = new Vector<String>();
		list.addElement("Vous etes chiant\n");
		list.addElement("Merci\nde rien");
		list.addElement(" et on ");
		list.addElement("va direct vers\n");
		list.addElement("LA CATA\n");

		System.out.println("Number of element : " + list.size());

		// Treating the buffer content
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {

			// enter the current string into the buffer
			String string = (String) iterator.next();
			buff.append(string);

			buff.flip();

			// reading from the buffer
			char[] str = new char[2048];
			
			int i = 0;
			while (buff.hasRemaining()) {
				str[i++] = buff.get();
			}
			
			String s = new String(new String(str).substring(0, i));
			System.out.print(s);
			buff.clear();
		}
	}
}
